module.exports = {
  apps: [{
    name: 'ai_nuxt',
    script: '.output/server/index.mjs',
    instances: process.env.PM2_INSTANCES || 2,
    exec_mode: 'cluster',
    env: {
      NODE_ENV: 'development',
      PORT: process.env.PORT || 3000,
      JWT_SECRET: process.env.JWT_SECRET || 'yizhijiSecretKey'
    },
    env_production: {
      NODE_ENV: 'production',
      PORT: process.env.PORT || 3000,
      JWT_SECRET: process.env.JWT_SECRET || 'yizhijiSecretKey'
    },
    env_development: {
      NODE_ENV: 'development',
      PORT: process.env.PORT || 3000,
      JWT_SECRET: process.env.JWT_SECRET || 'yizhijiSecretKey'
    },
    // PM2 集群配置
    instance_var: 'PM2_INSTANCE_ID',
    // 优雅关闭配置
    kill_timeout: 5000,
    wait_ready: true,
    listen_timeout: 10000,
    // 内存限制
    max_memory_restart: '1G',
    // 日志配置
    log_file: './logs/combined.log',
    out_file: './logs/out.log',
    error_file: './logs/error.log',
    log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
    merge_logs: true,
    time: true,
    // 监控配置
    pmx: true,
    // 自动重启配置
    autorestart: true,
    watch: false,
    max_restarts: 10,
    min_uptime: '10s',
    // 本地测试时启用更详细的日志
    log_type: 'json',
    // 忽略某些信号（可选）
    ignore_watch: ['node_modules', 'logs'],
    // 实例之间的延迟启动（毫秒）
    instance_wait_ready: 3000
  }]
}